package com.shawn.admin.interceptor;

import com.shawn.model.entity.Admin;

public class ThreadContext {
    /**
     * 线程变量副本数据
     */
    private static final ThreadLocal<Admin> threadLocal = new ThreadLocal<>();

    public static void setAdmin(Admin admin){
        threadLocal.set(admin);
    }

    public static Admin getAdmin(){
        return threadLocal.get();
    }

    public static String getUsername(){
        if (threadLocal.get()!=null){
            return threadLocal.get().getUsername();
        }
        return null;
    }
    public static Long getId(){
        if (threadLocal.get()!=null){
            return threadLocal.get().getId();
        }
        return null;
    }
    public static void clear(){
        threadLocal.remove();
    }
}
